﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.UserSkins;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Ribbon.Gallery;
using System.Threading;
using System.Globalization;
using DevExpress.XtraEditors;
using System.Configuration;
using System.Data.SqlClient;
using QLTV.Forms.KeHoach;



namespace QLTV
{
    public partial class frmMain : MainBase
    {
        public frmMain()
        {

            InitializeComponent();


        }

        private void Main_Load(object sender, EventArgs e)
        {

            //load bonus skins
            GalleryDropDown g = new GalleryDropDown();
            g.Ribbon = ribbon;
            DevExpress.XtraBars.Helpers.SkinHelper.InitSkinGalleryDropDown(g);
            btnSkinSelector.DropDownControl = g;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.StyleChanged += Default_StyleChanged;
            //minimize ribbon
            ribbon.Minimized = true;
            //load welcome
            lblWelcome.Caption = String.Format("{0}:  {1}", rm.GetString("sWelcome", myCultureInfo), Program.EmployeeName);
            loadBanLamViec();
            //thong tin csdl
            string connString = ConfigurationManager.ConnectionStrings["QLTV.Properties.Settings.CrewManagmentConnectionString"].ConnectionString;
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connString);
            txtServer.Caption = builder.DataSource;


        }
        private void Default_StyleChanged(object sender, EventArgs e)
        {
            QLTV.Database.dsUsersTableAdapters.tblUserProfileTableAdapter tadProfile = new Database.dsUsersTableAdapters.tblUserProfileTableAdapter();
            tadProfile.setDefautTheme(DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName, Program.username);

        }
        private void loadBanLamViec()
        {
            Forms.frmBanLamViec f = new Forms.frmBanLamViec();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lblDateTime.Caption = (DateTime.Now.ToString("h:mm:ss tt, dd/MM/yyyy"));

        }

        private void btnDanhMuc_ItemClick(object sender, ItemClickEventArgs e)
        {


        }

        private void btnDanhSachNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            //Forms.HoSoNhanSu.frmDanhSachNhanSu f = new Forms.HoSoNhanSu.frmDanhSachNhanSu();
            //for (int i = 0; i < this.MdiChildren.Length; i++)
            //{
            //    if (f.Name == this.MdiChildren[i].Name)
            //    {
            //        this.MdiChildren[i].Activate();
            //        return;
            //    }
            //}
            //f.MdiParent = this;
            //f.Show();
        }

        private void btnThongTinCongTy_ItemClick(object sender, ItemClickEventArgs e)
        {
            //frmToChuc f = new frmToChuc();
            //f.Show();
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnPhanQuyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmPhanQuyen f = new frmPhanQuyen();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnBanLamViec_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            loadDanhMuc();
        }
        private void loadDanhMuc()
        {
            Forms.frmDanhMuc f = new Forms.frmDanhMuc();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnNguoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            Forms.BaoMat.frmUserList f = new Forms.BaoMat.frmUserList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();

        }

        private void nbiVessel_ItemChanged(object sender, EventArgs e)
        {
            Forms.KhaiBao.frmVessel f = new Forms.KhaiBao.frmVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiVessel_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void nbiVesselType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmVesselType f = new Forms.KhaiBao.frmVesselType();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiFlag_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmFlag f = new Forms.KhaiBao.frmFlag();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiEngine_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //Forms.KhaiBao.frmEngine f = new Forms.KhaiBao.frmEngine();

            //for (int i = 0; i < this.MdiChildren.Length; i++)
            //{
            //    if (f.Name == this.MdiChildren[i].Name)
            //    {
            //        this.MdiChildren[i].Activate();
            //        return;
            //    }
            //}
            //f.MdiParent = this;
            //f.Show();
        }

        private void nbiEngineMaker_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmEngineMaker f = new Forms.KhaiBao.frmEngineMaker();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiEngineType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmEngineType f = new Forms.KhaiBao.frmEngineType();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiThuyenVien_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCrewList f = new Forms.KhaiBao.frmCrewList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnDangXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Restart();
        }

        private void ribbon_Click(object sender, EventArgs e)
        {

        }

        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmLichCongTac f = new Forms.KhaiBao.frmLichCongTac();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem6_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmLichHenList f = new Forms.KhaiBao.frmLichHenList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiGroupVessel_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmGroupVessel f = new Forms.KhaiBao.frmGroupVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiCertificate_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificatecs f = new Forms.KhaiBao.frmCertificatecs();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiCertificateCrew_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificateCrew f = new Forms.KhaiBao.frmCertificateCrew();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiTrainingCourse_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmTrainingCourse f = new Forms.KhaiBao.frmTrainingCourse();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiTrainingCrew_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmOverviewTrainingPlan f = new Forms.KeHoach.frmOverviewTrainingPlan();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiRanhk_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void nbiRanhk_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmRank f = new Forms.KhaiBao.frmRank();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbi_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmContractList f = new Forms.KhaiBao.frmContractList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem7_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.frmBanLamViec f = new Forms.frmBanLamViec();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnBieuDoNS_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void btnInVinic_ItemClick(object sender, ItemClickEventArgs e)
        {
            QLTV.Reports.rpInVinic c = new Reports.rpInVinic();
            c.ShowPreview();
        }

        private void btnNotInVinic_ItemClick(object sender, ItemClickEventArgs e)
        {
            QLTV.Reports.rpNotInVinic c = new Reports.rpNotInVinic();
            c.ShowPreview();
        }

        private void btnTim_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void nbiPhong_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void barButtonItem1_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            Reports.rptCrewList4 r = new Reports.rptCrewList4();
            r.ShowPreview();
        }

        private void barButtonItem9_ItemClick(object sender, ItemClickEventArgs e)
        {
            Reports.rptTongHop r = new Reports.rptTongHop();
            r.ShowPreview();
        }

        private void navBarItem4_ItemChanged(object sender, EventArgs e)
        {

        }

        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmKeHoach f = new Forms.KeHoach.frmKeHoach();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    f.showDaiHan();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
            f.showDaiHan();
        }

        private void navBarItem10_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmKeHoach f = new Forms.KeHoach.frmKeHoach();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name && f.isLongPlan == false)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem11_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmPhongNghiepVu f = new Forms.KhaiBao.frmPhongNghiepVu();
            f.ShowDialog();
        }

        private void navBarItem12_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.BaoMat.frmUserList f = new Forms.BaoMat.frmUserList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem13_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmVessel f = new Forms.KhaiBao.frmVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void frmMain_MdiChildActivate(object sender, EventArgs e)
        {

        }

        private void navBarItem3_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmKeHoach f = new Forms.KeHoach.frmKeHoach();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    f.ShowNganHan();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
            f.ShowNganHan();

        }

        private void barMdiChildrenListItem1_ListItemClick(object sender, ListItemClickEventArgs e)
        {

        }

        private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
        {
            //if ((Int32)txtPlanID.EditValue > 0)
            //{
            Reports.rptTraining r = new Reports.rptTraining();
            //r.CreatedDate = (DateTime)txtNgayLap.EditValue;
            //r.CourseName = txtMonHoc.Text;
            r.loadData(11);
            r.ShowPreview();
            //}
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Database.dsUsersTableAdapters.tblUsersTableAdapter tadUser = new Database.dsUsersTableAdapters.tblUsersTableAdapter();
            if (tadUser.selectPass(Program.username) == txtOld.EditValue.ToString())
            {
                if (dxValidationProvider1.Validate())
                {
                    tadUser.ChangePass(txtNew.EditValue.ToString(), Program.username);
                    XtraMessageBox.Show(rm.GetString("sMessageSuccess", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo));
                    popupChangePass.Hide();
                }
            }
            else
                XtraMessageBox.Show(rm.GetString("sPassConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo));
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            popupChangePass.Hide();
        }

        private void btnDoiMatKhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            popupChangePass.Show();
        }

        private void barButtonItem1_ItemClick_2(object sender, ItemClickEventArgs e)
        {
            frmLoginSql f = new frmLoginSql();
            f.ShowDialog();
        }

        private void btnSaoLuu_ItemClick(object sender, ItemClickEventArgs e)
        {
            SQLServerDatabaseBackup.frmBackup f = new SQLServerDatabaseBackup.frmBackup();
            f.ConnString = ConfigurationManager.ConnectionStrings["QLTV.Properties.Settings.CrewManagmentConnectionString"].ConnectionString;
            f.ShowDialog();
        }

        private void btnPhucHoi_ItemClick(object sender, ItemClickEventArgs e)
        {

            SQLServerDatabaseBackup.frmRestore f = new SQLServerDatabaseBackup.frmRestore();
            f.ShowDialog();
            Application.Restart();
        }

        private void navBarItem2_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmRankCourse r = new frmRankCourse();
            r.StartPosition = FormStartPosition.CenterScreen;
            r.ShowDialog();
        }

        private void barButtonItem9_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            //   SchedulerReportDesignTool t = new SchedulerReportDesignTool();
        }

        private void navBarItem2_LinkClicked_2(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificateCrew f = new Forms.KhaiBao.frmCertificateCrew();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
        {
            Reports.rpt r = new Reports.rpt();
            
           r.loadData();
            r.ShowPreview();

        }

        private void navBarItem2_LinkClicked_3(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificatecs f = new Forms.KhaiBao.frmCertificatecs();
            f.StartPosition = FormStartPosition.CenterParent; 
            f.ShowDialog();
        }

        private void navBarItem3_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmNhatKy f = new Forms.KhaiBao.frmNhatKy();
            f.StartPosition = FormStartPosition.CenterParent;
            f.Show();
        }



    }
}
